<template>
  <div class="goodsDetail">
    <div>
      <div class="mt20">
        <span class="main_active">商户名称：</span>
        <el-select
          v-model="formInfo.comid"
          class="w400"
          placeholder="请选择"
          @change="changeConpany"
        >
          <el-option
            v-for="item in Companylist"
            :key="item.CompanyId"
            :label="item.FullName"
            :value="item.CompanyId"
          />
        </el-select>
      </div>
      <div class="mt20">
        <span class="main_active">部门名称：</span>
        <el-select v-model="formInfo.deptid" class="w400" placeholder="请选择">
          <el-option
            v-for="item in DepartmentList"
            :key="item.DepartmentId"
            :label="item.FullName"
            :value="item.DepartmentId"
          />
        </el-select>
      </div>
    </div>
    <div class="tableDetail">
      <div class="button-add">
        <el-button size="small" type="primary" @click="addFn()">
          添加行
        </el-button>
        <!-- <el-button size="small" type="danger" @click="deletedchild()">
          删除行
        </el-button> -->
      </div>
      <el-scrollbar
        wrap-class="scrollbar-wrapper"
        wrap-style="overflow-x: auto;"
      >
        <el-table
          ref="multipleTable"
          border
          :data="tableData"
          height="400"
          :row-class-name="tableRowClassName"
          :row-key="getRowKey"
          style="width: 550px"
          @selection-change="handleSelectionChange"
        >
          <!-- <el-table-column prop="value" type="selection" width="55" /> -->
          <el-table-column label="编号" type="index" width="50" />
          <el-table-column label="射频码">
            <template #default="{ row }">
              <el-input v-model="row.ESLCode" type="text" />
            </template>
          </el-table-column>
        </el-table>
      </el-scrollbar>
    </div>
  </div>
</template>
<script>
  import { CompanyData, DepartmentData } from '@/api/eslstock'
  export default {
    name: 'Detail',
    components: {},
    props: {
      form: {
        type: Object,
        default: () => {
          return {}
        },
      },
      dialogss: {
        type: Boolean,
        default: false,
      },
    },
    emits: ['deletedchild'],
    data() {
      return {
        formInfo: this.form,
        tableData: this.form.chiledData,
        Companylist: [],
        DepartmentList: [],
      }
    },
    watch: {
      form(val) {
        console.log(val)
        this.formInfo = val
        this.tableData = val.chiledData
      },
    },
    created() {
      this.CompanyData()
    },
    methods: {
      //  选中公司
      changeConpany(val) {
        console.log(val)
        this.formInfo.comid = val
        this.DepartmentData(val)
      },
      addFn() {
        this.$nextTick(() => {
          this.tableData.push({
            ESLCode: '',
          })
        })
      },
      async CompanyData() {
        const params = {
          pageNo: 0,
          pageSize: 0,
          total: 0,
          tableName: '',
          sort: '',
          order: '',
          wheres: '',
          export: true,
          value: '',
        }
        const data = await CompanyData(params)
        if (data.code === '200') {
          console.log(data)
          // this.formInfo.comid = data.data.rows[0].CompanyId
          this.Companylist = data.data.rows
          // this.DepartmentData(data.data.rows[0].CompanyId)
        }
      },
      async DepartmentData(val) {
        const params = {
          pageNo: 0,
          pageSize: 0,
          total: 0,
          tableName: '',
          sort: '',
          order: '',
          wheres: '',
          export: true,
          value: val,
        }
        const data = await DepartmentData(params)
        if (data.code === '200') {
          console.log(data)
          this.DepartmentList = data.data.rows
          this.formInfo.deptid = data.data.rows[0].DepartmentId
        }
      },
    },
  }
</script>
<style lang="scss" scoped>
  .goodsDetail {
    min-height: 300px;
  }
  .flex_align {
    display: flex;
    align-items: center;
  }
  .tableDetail {
    padding: 10px;
    .button-add {
      text-align: end;
      padding: 10px;
    }
  }
  .main_active {
    display: inline-block;
    width: 120px;
    text-align: right;
  }
  .mr20 {
    margin-right: 20px;
  }

  .w400 {
    width: 400px !important;
  }
  .mt20 {
    margin-top: 10px;
  }
  .mr10 {
    margin-right: 10px;
  }
  .w320 {
    width: 320px;
  }
  ::v-deep .el-scrollbar__wrap {
    overflow-x: auto;
    height: calc(100% + 20px); //多出来的20px是横向滚动条默认的样式
  }
  ::v-deep .el-scrollbar .el-scrollbar__wrap .el-scrollbar__view {
    white-space: nowrap;
    display: inline-block;
  }
  ::v-deep .el-table--scrollable-x .el-table__body-wrapper {
    overflow-x: hidden;
  }
  ::v-deep input[type='number']::-webkit-inner-spin-button,
  ::v-deep input[type='number']::-webkit-outer-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
  }
</style>
